/*
 * FileDetailsTable.java
 *
 * Created on 15 April 2007, 17:16
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.cardcopier.ui;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.JTextField;
import org.cardcopier.CardCopier;
import org.cardcopier.CardCopierModel;
import org.cardcopier.CardCopierModelListener;
import org.cardcopier.file.ByteSizeFormatter;
import org.cardcopier.file.FileUtils;

/**
 *
 * @author Mark
 */
public class UICardCopierModelListener implements CardCopierModelListener {
    
    private final JLabel spaceAvailableLabel;
    private final JTextField destination;
    private final FileDetailsTable table;
    private final JLabel messageText;
            
    private final ByteSizeFormatter sizeFormatter = new ByteSizeFormatter();
    
    /** Creates a new instance of FileDetailsTable */
    public UICardCopierModelListener(JTextField destination, JLabel spaceAvailableLabel, FileDetailsTable table, JLabel messageText) {
        this.spaceAvailableLabel = spaceAvailableLabel;
        this.destination = destination;
        this.table = table;
        this.messageText = messageText;
    }
    
    public void sourceLocationChanged(CardCopierModel cardCopierModel) {
        table.setFileStates(cardCopierModel.getFileStates());
    }

    public void destinationLocationChanged(CardCopierModel cardCopierModel) {
        destination.setText(cardCopierModel.getFullDestinationDir().getDirectory().getAbsolutePath());
        table.setFileStates(cardCopierModel.getFileStates());
        long spaceAvailable = cardCopierModel.getSpaceAvailableInDestination();
        String spaceAvailabletext = "Could not calculate space available in destination";
        if (spaceAvailable >= 0) {
            spaceAvailabletext = sizeFormatter.format(spaceAvailable) + " of disk space available";
        }
        spaceAvailableLabel.setText(spaceAvailabletext);
    }

    public void messageTextChanged(CardCopierModel cardCopierModel) {
        messageText.setText(cardCopierModel.getMessageText());
    }

    public JTextField getDestination() {
        return destination;
    }
    

}
